all_sites={};
for dnd=1:4
    cur_site=dnd;
    res_mat={};
    %vis_resp,run_resp,blink_resp,eye_resp,fdbk_resp,blink_dark_resp,eye_dark_resp,run_dark_resp,fb_snips,pb_snips
    blink_mat={};
    blink_dark_mat={};
    [~,res_mat{1},res_mat{2},blink_mat{1},blink_mat{2},res_mat{4},blink_dark_mat{1},blink_dark_mat{2},res_mat{6},res_mat{7},res_mat{8}]=meta_get_cell_type_onset(proj_meta,cur_site);
    num_tp=size(res_mat{1},2);
    num_cell=size(res_mat{1},1);
    
    cur_eye={};
    cur_eye_dark={};
    for ynd=1:num_tp
        for jnd=1:num_cell
            cur_eye{jnd,ynd}=[blink_mat{1}{jnd,ynd};blink_mat{2}{jnd,ynd}];
            cur_eye_dark{jnd,ynd}=[blink_dark_mat{1}{jnd,ynd};blink_dark_mat{2}{jnd,ynd}];
        end
    end
    res_mat{3}=cur_eye;
    res_mat{5}=cur_eye_dark;
    
    num_tp=size(res_mat{1},2);
    num_cell=size(res_mat{1},1);
    sig_num={};
    for gnd=1:num_tp
        for vnd=1:num_cell
            cnt=7;
            for und=1:8
                if und<7
                    cur_traces=res_mat{und}{vnd,gnd};
                    if ~isempty(cur_traces)
                        cur_diff=(mean(cur_traces(:,15:20),2)-mean(cur_traces(:,5:10),2))';
                        %                     cur_diff(cur_diff<0)=NaN;
                        sig_num{und,gnd}(vnd,:)=cur_diff;
                    else
                        sig_num{und,gnd}=[];
                    end
                else
                    for knd=1:13
                        cur_traces=res_mat{und}{vnd,gnd}{knd}';
                        if ~isempty(cur_traces)
                            cur_diff=(mean(cur_traces(:,20:25),2)-mean(cur_traces(:,10:15),2))';
                            %                         cur_diff(cur_diff<0)=NaN;
                            sig_num{cnt,gnd}(vnd,:)=cur_diff;
                            cnt=cnt+1;
                        else
                            sig_num{cnt,gnd}=[];
                            cnt=cnt+1;
                        end
                    end
                end
            end
        end
    end
    sig_p=[];
    sig_mu=[];
    for gnd=1:num_tp
        for vnd=1:num_cell
            for und=1:size(sig_num,1)
                if ~isempty(sig_num{und,gnd})
                    cur_diff=sig_num{und,gnd}(vnd,:);
                    cur_diff(cur_diff<0)=[];
                    [~,sig_p(vnd,und,gnd)]=ttest(cur_diff);
                    sig_mu(vnd,und,gnd)=mean(cur_diff);
                else
                    sig_p(vnd,und,gnd)=NaN;
                    sig_mu(vnd,und,gnd)=NaN;
                end
            end
        end
    end
    all_sites{1,dnd}=num_cell;
    all_sites{2,dnd}=sig_p;
    all_sites{3,dnd}=sig_mu;
end

all_p=[];
all_mu=[];
all_cells=[];
xp_cnt=0;
xm_cnt=0;
for dnd=1:4
    cur_p=all_sites{2,dnd};
    cur_mu=all_sites{3,dnd};
    [xp]=size(cur_p);
    [xm]=size(cur_mu);
    all_p(xp_cnt+1:xp_cnt+xp,:,:)=cur_p(:,:,1:3);
    all_mu(xm_cnt+1:xm_cnt+xm,:,:)=cur_p(:,:,1:3);
    xp_cnt=xp_cnt+xp;
    xm_cnt=xm_cnt+xm;
    all_cells(1)=sum([all_cells all_sites{1,dnd}]);
end

%vis_resp,run_resp,blink/eye_resp,fdbk_resp,blink/eye_dark_resp,run_dark_resp,fb_snips,pb_snips
figure;scatter(all_mu([1:1203 1700:2102],19,1),all_mu([1:1203 1700:2102],32,1))

figure;scatter(sig_p(:),sig_mu(:))

figure;hist(sig_p(:),50)

sum(sig_p(:)<0.001)





